<template>
  <li>
    <div :class="['org-tree']">
      <OrgTreeOptionSub v-for="(item,i) in treelist" :key="`org-tree-${Math.random()}-children-${item.id}`" :data="item"></OrgTreeOptionSub>
    </div>
  </li>
</template>

<style lang="less" src="@/assets/styles/org-tree.less"></style>
<script>
	import {mapState,mapActions} from 'vuex'

  export default {
    props:{
      onlyLast:{type:Boolean,default:true}
    },
    data(){
      return {

      }
    },
    computed:{
      ...mapState('base',['userinfo']),
      parentId(){
        return this.userinfo.org.parentId;
      },
      treelist(){
        let list = this.createTreeList(this.parentId);
        return list;
      }
    },
    methods:{
      createTreeList(pid){
        let ary = [];
        this.userinfo.lowerOrgs.forEach(o => {
          let item = {...o};
          if (this.onlyLast) {
            item.disabled = item.orgType !== 2;
          }
          if (item.parentId === pid) {
            item.children = this.createTreeList(item.id);
            ary.push(item);
          }
        });
        return ary;
      }
    }
  }
</script>
